home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / diskutil / ff32src.zoo / dspeed.c < prev    next >
C/C++ Source or Header  |  1991-03-16  |  4KB  |  146 lines

  1. /*
  2.     Find the disk speed, in RPM (revolutions per minute)
  3.     Copyright (C) 1989  by Robert Fischer
  4.  
  5.     This program costs no money; you can redistribute it and/or modify it
  6.     under the terms of the Lynxware General License as published by Robert
  7.     Fischer; either version 1, or (at your option) any later version. 
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     Lynxware General License for more details.
  13.  
  14.     You should have received a copy of the Lynxware General License
  15.     along with this program; if not, write to the author.
  16.  
  17.     To contact the author, call or write:
  18.         Robert Fischer
  19.         80 Killdeer Road
  20.         Hamden, CT    06517
  21.         (203) 288-9599
  22.         E-mail: fischer-robert@cs.yale.edu
  23. */
  24.  
  25. #include <stdio.h>
  26.  
  27. /* ================= Pulled from my Include files ================== */
  28. #define HZ_200          *( (LONG *)0x4BAL )
  29.  
  30. #define Cconout(a)          gemdos(0x2,a)
  31. #define Cnecin()            gemdos(0x8)
  32. #define Cconws(a)           gemdos(0x9,a)
  33. #define Super(a)            gemdos(0x20,(LONG)(a))
  34. #define Dfree(a,b)          gemdos(0x36,a,b)
  35. #define Getbpb(a)           bios(7,a)
  36. #define Rwabs(a,b,c,d,e)    bios(4,a,(LONG)b,c,d,e)
  37.  
  38. #   define B_READ 0
  39. #   define B_WRITE 1
  40. #   define B_READ_NOCHANGE 2
  41. #   define B_WRITE_NOCHANGE 3
  42. #   define FLOP_A 0
  43. #   define FLOP_B 1
  44.  
  45. extern char *lmalloc();
  46. extern long bios();
  47. extern long xbios();
  48. extern long gemdos();
  49.  
  50. typedef unsigned long LONG;
  51.  
  52. /* ------------------------------------------------------- */
  53. static char address[] = "\
  54.                   80 Killdeer Road\r\n\
  55.                   Hamden, CT  06517  USA\r\n\
  56.                   (203) 288-9599\r\n";
  57. char buf[512];
  58. #define NUM_TIMES 100
  59. #define COPYRIGHT 0xbd
  60. /* ----------------------------------------------------------- */
  61. waituser()
  62. {
  63.     printf("(Please press <return> to continue)");
  64.     getchar();
  65. }
  66. /* ------------------------------------------------------- */
  67. usage()
  68. {
  69.         Cconws("DSPEED floppy drive speed check 1.0 Copyright \275 1989 by Robert Fischer\r\n");
  70.         Cconws(address);
  71.         Cconws("DSPEED comes with ABSOLUTELY NO WARRANTY.\r\n"
  72.         "This program is Lynxware and is subject to the terms of the Lynxware\r\n"
  73.         "General License; either version 1, or (at your option) any later version.\r\n\n"
  74.         );
  75.         Cconws("Usage:  DSPEED drive[:]\r\n");
  76.         waituser();
  77.         exit(1);
  78. }
  79. /* ----------------------------------------------------------- */
  80. long clock()
  81. {
  82. LONG usp;
  83. long ret;
  84.     usp = Super(0);
  85.     ret = HZ_200;
  86.     Super(usp);
  87.     return ret;
  88. }
  89. /* ------------------------------------------------------- */
  90. move_disk(drive)
  91. int drive;
  92. {
  93. long err;
  94.    
  95.     if (err = Rwabs(B_READ, buf, 1, 17, drive)) {
  96.         printf("Disk error # %ld -- aborting dspeed\n", err);
  97.         waituser();
  98.         exit(1);
  99.     }
  100. }
  101. /* ----------------------------------------------------------- */
  102. int
  103. testdisk(drive)
  104. int drive;
  105. {
  106. int i;
  107. long start_time;
  108. long time;
  109. int rpm;
  110.     Dfree(buf, drive+1);    /* Recognize new disk, if any */
  111.     move_disk(drive);       /* Get drive started and up to speed */
  112.  
  113.     start_time = clock();   /* Time NUM_TIMES accesses */
  114.     for (i = 0; i < NUM_TIMES; i++) move_disk(drive);
  115.     time = clock();
  116.  
  117.     rpm = ((NUM_TIMES * 24000L) / (time - start_time) + 1L) / 2L;
  118.     return rpm;
  119. }
  120. /* ----------------------------------------------------------- */
  121. main(argc, argv)
  122. int argc;
  123. char *argv[];
  124. {
  125.     int drive;
  126.     int rpm;
  127.     
  128.     if (argc <= 1 || argc >= 3) usage();
  129.     switch (*(argv[1])) {
  130.         case 'A':
  131.         case 'a':   drive = FLOP_A; break;
  132.         case 'B':
  133.         case 'b':   drive = FLOP_B; break;
  134.         default :   usage();
  135.     }
  136.     
  137.     printf("Please insert a disk in drive %c: and press <return>",
  138.              'A'+drive);
  139.     getchar();
  140.     printf("Please wait --- the disk will run for approximately %d seconds\n",
  141.             NUM_TIMES/5);
  142.     rpm = testdisk(drive);
  143.     printf("The disk spins at %d RPM\n", rpm);
  144.     waituser();
  145. }
  146.